# -*-coding: Utf-8 -*-
# @File : celery .py
# author: Chimengmeng
# blog_url : https://www.cnblogs.com/dream-ze/
# Time：2024/7/3

import os
# pip install Celery
from celery import Celery
from celery.schedules import crontab

# celery 使用 Django 需要 注册Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ShortLink.settings.develop')

# 消息中间件
broker = "redis://127.0.0.1:6379/0"
# 存储结果
backend = "redis://127.0.0.1:6379/1"
# 存放需要处理任务的列表
include = ['celery_task.user_task']
# 实例化得到celery对象
app = Celery(__name__, backend=backend, broker=broker, include=include)

# APP 配置 +---+ 定时任务配置
# app.conf.beat_schedule = {
#     'send_sms': {
#         # 执行的任务函数
#         'task': 'celery_task.user_task.send_sms',
#         # 延迟时间
#         # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
#         # 'schedule': crontab(hour=11, minute=35),  # 每天11点35，执行
#         'schedule': timedelta(seconds=5),
#         'args': ('1822344343', 8888),
#     },
# }
